package com.fxu.tpl.rest;

import cn.hutool.core.util.StrUtil;
import com.fxu.framework.biz.rest.ApiBizRest;
import com.fxu.framework.core.base.Result;
import com.fxu.framework.core.service.impl.ApiServiceImpl;
import com.fxu.tpl.entity.Project;
import com.fxu.tpl.enums.ProjectTypeEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/***
 * <p>fxu</p>
 * 项目表：[project]的业务逻辑接口实现
 * @author fangxu
 * @version 2019-09-23
 ***/
@Slf4j
@Component
@RequiredArgsConstructor
public class ProjectRestImpl implements ApiBizRest<Project> {
/*=== 自动生成代码 开始 ===*/
/*=== 自动生成代码 结束 ===*/

	private final ApiServiceImpl apiRestImpl;
	@Override
	public Result<Project> saveBefore(Project oldBean, Project bean) {
		if (bean != null) {
			if (!StrUtil.isEmpty(bean.getVuePath()) && !bean.getVuePath().endsWith("/")) {
				bean.setVuePath(bean.getVuePath() + "/");
			}
			if (!StrUtil.isEmpty(bean.getDstPath()) && !bean.getDstPath().endsWith("/")) {
				bean.setDstPath(bean.getDstPath() + "/");
			}
			/*if (!StrUtil.isEmpty(bean.getTplPath())) {
				if (!bean.getTplPath().endsWith("/")) {
					bean.setTplPath(bean.getTplPath() + "/");
				}
				bean.setVueTpl(bean.getTplPath() + "index.vue");
			}*/
			//TODO 删除字段 [tplPath, vueTpl, tplFacade, tplRest, tplService]
			bean.setTplClass("Test");
			bean.setTplProject("fxu");
			bean.setTplModule("tpl");
			bean.setTplFacade("fxu-generator");
			bean.setTplRest("fxu-generator");
			bean.setTplService("fxu-generator");
			ProjectTypeEnum projectType = ProjectTypeEnum.find(bean.getType());
			if (projectType == ProjectTypeEnum.SPRING_CLOUD) {
				bean.setTplFacade("fxu-cloud-facade");
				bean.setTplRest("fxu-cloud-user");
				bean.setTplService("fxu-cloud-user");
			} else if (projectType == ProjectTypeEnum.SPRING_DUBBO) {
				bean.setTplFacade("fxu-dubbo-facade");
				bean.setTplRest("fxu-dubbo-user");
				bean.setTplService("fxu-dubbo-user");
			}
		}
		return Result.ok(bean);
	}
}
